#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
筛选href.txt中包含cqut的链接并保存到href_nice.txt
"""

import os
def href_nice():
    count_total = 0
    count_cqut = 0
    script_dir = os.path.dirname(os.path.abspath(__file__))
    # 边读边写，避免内存堆积
    with open(script_dir + "/../href.txt", 'r', encoding='utf-8') as input_file, \
        open(script_dir + "/../href_nice.txt", 'w', encoding='utf-8') as output_file:
        
        for line in input_file:
            link = line.strip()
            if link:
                count_total += 1
                if 'cqut' in link.lower() and (link.startswith('https://') or link.startswith('http://')):  
                    output_file.write(link + '\n')
                    count_cqut += 1

    print(f"筛选完成: {count_total} -> {count_cqut} 个链接")

if __name__ == "__main__":
    href_nice()

